package yawning.mew.bear;

import yawning.mew.bear.BearThreatSimulation.SimulatorProperty;
import yawning.mew.character.CharacterModel.AttackResult;
import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class DemoralizingRoarAction extends SimulationEventAction {
	BearThreatSimulator mState;
	boolean mExternal;

	public DemoralizingRoarAction(BearThreatSimulator state) {
		super(state.mSimEngine);
		mState = state;
		mExternal = mState.mSimEngine.getConfig().getBool(SimulatorProperty.ASSUMEEXTERNALDEMO);
		if (mExternal) {
			schedule(Double.MAX_VALUE);

			if (mState.mIsLogging) mState.mLog.log("Demoralizing Roar: External\n");
		}
	}

	@Override
	public double perform() {
		if (!mState.hasRage(mState.mModel.demoralizingRoarCost)) return SimulationAction.ACTION_FAIL;

		AttackResult result = mState.mModel.getSpellResult();

		switch (result) {
		case MISS:
			mNrDemoMiss++;

			if (mState.mIsLogging) mState.mLog.log("Demoralizing Roar: MISS\n");
			break;
		case HIT:
		case CRIT:
			mNrDemoHit++;

			if (isUp()) cancel();

			if (mState.mIsLogging) mState.mLog.log("Demoralizing Roar: HIT\n");

			mState.mModel.multiplyIncPhysicalDamage(mState.mModel.multDemoralizingRoarDR);

			schedule(mState.mModel.demoralizingRoarDebuffDuration);

			break;
		}

		mState.onRageLoss(mState.mModel.demoralizingRoarCost, false);

		return 1.5;
	}

	@Override
	public void onExpire() {
		mState.mModel.multiplyIncPhysicalDamage(1.0f / mState.mModel.multDemoralizingRoarDR);

		if (mState.mIsLogging) mState.mLog.log("Demoralizing Roar Expiration\n");
	}

	int mNrDemoHit = 0;
	int mNrDemoMiss = 0;
}
